﻿// ***********************************************************************
// Assembly         : OSS.BIM
// Author           : tian_
// Created          : 09-05-2018
//
// Last Modified By : tian_
// Last Modified On : 09-05-2018
// ***********************************************************************
// <copyright file="PropertyAddCmd.cs" company="北京智帆高科科技有限公司">
//     Copyright © 北京智帆高科科技有限公司 2018
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OSS.BIM.Model;
using OSS.BIM.UI.Controls;
using OSS.BIM.UI.Forms;
using ZFGK.Addins;

namespace OSS.BIM.Commands.PropertyCmds
{
    /// <summary>
    /// Class PropertyAddCmd.
    /// </summary>
    /// <seealso cref="ZFGK.Addins.IExtendCommand" />
    public class PropertyAddCmd : IExtendCommand
    {
        /// <summary>
        /// Executes the specified command data.
        /// </summary>
        /// <param name="cmdData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <returns>CmdResult.</returns>
        public CmdResult Execute(ExtendCmdData cmdData, ref string message)
        {
            var mainForm = cmdData.ViewForm as Form;

            var propertyForm = new PropertyForm("", "", true);
            propertyForm.Icon = mainForm.Icon;
            if (propertyForm.ShowDialog(mainForm) != DialogResult.OK)
                return CmdResult.Cancel;

            var modelProperty = new ModelProperty();
            modelProperty.Name = propertyForm.Key;
            modelProperty.DiaplayLable = propertyForm.Key;
            modelProperty.Value = propertyForm.Value;
            modelProperty.ValueType = 0;

            PropertiesGridControl.Instance.gridControl.BeginUpdate();
            PropertiesGridControl.Instance.Properties.Add(modelProperty);
            PropertiesGridControl.Instance.gridControl.DataSource = null;
            PropertiesGridControl.Instance.gridControl.DataSource = PropertiesGridControl.Instance.Properties;
            PropertiesGridControl.Instance.Chenged = true;
            PropertiesGridControl.Instance.gridControl.EndUpdate();

            return CmdResult.Succeed;
        }
    }
}
